class PkRelation < ActiveRecord::Base
    belongs_to :paper
    belongs_to :p_keyword
    
    def self.add_reference(paperid,word)
      keywordid=PKeyword.add_ref_count(word)
      pkrelation=PkRelation.new()
      pkrelation.keyword_id=keywordid
      pkrelation.paper_id=paperid
      pkrelation.save
    end

    def self.alter_relation(paperid,oldkeywords,keywords)
      PkRelation.destroy_all ["paper_id=?",paperid]
      for oldkeyword in oldkeywords
        PKeyword.sub_ref_count(oldkeyword)
      end
      for keyword in keywords
        add_reference(paperid,keyword)
      end
    end
    
end
